package com.walk.zworld.ui.activity

import android.widget.EditText
import com.walk.zworld.R
import com.walk.zworld.mvvm.vm.ShareActivityViewModel
import com.base.lib.base.view.BaseMvvmActivity

class ShareActivity : BaseMvvmActivity<ShareActivityViewModel>() {


    override fun onBindLayout(): Int = R.layout.activity_share

    override fun onBindViewModel(): Class<ShareActivityViewModel>  = ShareActivityViewModel::class.java

    override fun initData() {
        setTop("分享文章", "分享")
        setRight("分享"){
            shareArticle()
        }
    }

    override fun initView() {}

    private fun shareArticle() {
        val title = findViewById<EditText>(R.id.et_article_title).text.toString().trim()
        val link = findViewById<EditText>(R.id.et_article_link).text.toString().trim()
        if (title.isEmpty()) {
            toast("文章标题不能为空")
            return
        }
        if (link.isEmpty()) {
            toast("文章链接不能为空")
            return
        }
        val map = mutableMapOf<String, Any>()
        map["title"] = title
        map["link"] = link
        mViewModel.shareArticle(map).observe(this) {
            toast("提交成功")
            setResult(RESULT_OK)
            this@ShareActivity.finish()
        }
    }
}